#pragma once
#include <stdexcept>

class ContextTreeNode
{
public:
	ContextTreeNode(ContextTreeNode *prnt);
	~ContextTreeNode(void);

	bool isRoot(){return parent==0l;}
	bool isLeaf(){return leftChild==0l && rightChild==0l;}

	void addOne(){onesCount++;}
	void addZero(){zerosCount++;}

	void removeOne(){onesCount--;}
	void removeZero(){zerosCount--;}

	int getOnesCount(){return onesCount;}
	int getZerosCount(){return zerosCount;}

	void setProbability(float prob){probability=prob;}
	double getProbability(){return probability;}

	void setLeftChild(ContextTreeNode *lChild);
	void setRightChild(ContextTreeNode *rChild);
	
	ContextTreeNode * getLeftChild(){return leftChild;}
	ContextTreeNode * getRightChild(){return rightChild;}
	ContextTreeNode * getParent(){return parent;}
	
	void clearNode();

	float countLUT(int zeros, int ones);
	void countAndSetProbability(double lutValue);

private:
	ContextTreeNode *parent;
	ContextTreeNode *leftChild, *rightChild;

	float probability;
	int onesCount, zerosCount;

public:
	class ChildOverwriting : public std::runtime_error
	{
	public:
		ChildOverwriting():std::runtime_error("Attempt to overwrite child in tree!"){}
		~ChildOverwriting(){};
	};
};

